//
//  AViewController.m
//  MPTCustomUILibrary
//
//  Created by 龙鹏飞 on 2017/9/15.
//  Copyright © 2017年 jxzjxz. All rights reserved.
//

#import "AViewController.h"
#import "MPCNavigationBar.h"
#import "BViewController.h"
#import <Masonry.h>

@interface AViewController ()<UITableViewDelegate,UITableViewDataSource,MPCNavigationBarDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) MPCNavigationBar *bar;

@end

@implementation AViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:NO];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    
    
    [self.view addSubview:self.tableView];

    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.and.trailing.and.bottom.equalTo(self.view);
        make.top.equalTo(self.view.mas_top).offset(64);
    }];
    
    self.tableView.clipsToBounds = NO;
    
    [self navigatonBarStyle];
}

- (void)navigatonBarStyle
{
    MPCNavigationBar *bar = [[MPCNavigationBar alloc] initNavigationBarWithViewController:self title:@"页面A" leftBarButtonImageName:@"MPTCommonBack" leftBarButtonHighlightedImageName:nil rightBarButtonImageName:@"MPTTopicShare" rightBarButtonHighlightedImageName:nil needStatusBar:YES];
    bar.backgroundImage = [UIImage imageNamed:@"barImage.jpeg"];
    bar.needBlur = YES;
    bar.delegate = self;
    self.bar = bar;
}

- (void)rightBarButtonDidClicked:(UIButton *)button
{
    BViewController *con = [[BViewController alloc]init];
    [self.navigationController pushViewController:con animated:YES];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat alpha = (400 - scrollView.contentOffset.y) / 400;
    alpha = alpha < 0 ? 0 : alpha > 1 ? 1 : alpha;
    [self.bar setBarAlpha:alpha];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return  200;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.textLabel.text = [@(indexPath.row+1).stringValue stringByAppendingString:@"**************************"];
    return cell;
}

- (UITableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    }
    return  _tableView;
}

@end
